import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useCounterStore = defineStore(
  'counter',
  () => {
    // 组合式 API 写法
    // ref
    const num1 = ref(11111)
    const num2 = ref(22222)

    // 定义 state
    const count = ref(100)

    // 定义 getters
    const double = computed(() => count.value * 2)

    // 定义 actions
    const addCount = () => {
      count.value++
    }

    const decrement = () => {
      count.value--
    }

    // 千万不要忘记这里要 return
    return { count, double, addCount, decrement }
  },
  {
    // 新的unistorage 插件持久化配置

    // unistorage:true 所有的都存储

    unistorage: {
      key: 'counter', //存储的key
      paths: ['count'], //存储指定的ref
    },
  }
)
